using System.Collections.Generic;
using System.Linq;
using Managistics.Core.Infrastructure;
using Managistics.Core.Repositories;
using Managistics.Core.Services;
using Managistics.Model;

namespace Managistics.Core.Services.Impl
{
    public class SaleOrderService : ISaleOrderService
    {
        private readonly ISaleOrderRepository _saleOrderRepository;

        public SaleOrderService(ISaleOrderRepository saleOrderRepository)
        {
            _saleOrderRepository = saleOrderRepository;
        }
        
        [UnitOfWork]
        public SaleOrder GetOrderById(string orderId)
        {
            return _saleOrderRepository.GetOrderById(orderId);
        }

        public void CreateOrder(SaleOrder order)
        {
            /* Not used UnitOfWork attribute, because this method only calls one repository method and repoository can manage it's connection/transaction. */
            _saleOrderRepository.Insert(order);
        }

        public void UpdateOrder(SaleOrder order)
        {
            /* Not used UnitOfWork attribute, because this method only calls one repository method and repoository can manage it's connection/transaction. */
            _saleOrderRepository.Update(order);
        }

        [UnitOfWork]
        public void DeleteOrder(string orderId)
        {
            /* Used UnitOfWork attribute, because we use different repositories and all operations must be transactional. */
            _saleOrderRepository.Delete(orderId);
        }
    }
}